//
//  CommonUserInfo.m
//  quxiangtao
//
//  Created by xbmios on 2018/8/16.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "CommonUserInfo.h"

#define UserDefault_Access_token      @"UserDefault_Access_token"
#define UserDefault_OpenID            @"UserDefault_OpenID"
#define UserDefaul_isLogin            @"UserDefaul_isLogin"
#define UserDefaul_User_name          @"UserDefaul_User_name"
#define UserDefault_Phone             @"UserDefault_Phone"
#define UserDefault_Is_setPayPassword @"UserDefault_Is_setPayPassword"
#define UserDefault_VIPLevel          @"UserDefault_VIPLevel"
#define UserDefault_Is_Bind           @"UserDefault_Is_Bind"
#define UserDefault_NickName          @"UserDefault_NickName"
#define UserDefault_PhotoUrl          @"UserDefault_PhotoUrl"
#define UserDefault_Balance           @"UserDefault_Balance"
#define UserDefault_BeanNum           @"UserDefault_BeanNum"
#define UserDefault_Token             @"UserDefault_Token"
#define UserDefault_UserInforModel    @"UserDefault_UserInforModel"
#define UserDefault_User_id           @"UserDefault_User_id"
#define UserDefault_IconIV            @"UserDefault_IconIV"
#define UserDefault_UserType          @"UserDefault_UserType"
#define UserDefault_UserLv            @"UserDefault_UserLV"
#define UserDefault_Bean_quota        @"UserDefault_Bean_quota"


@implementation CommonUserInfo

+ (instancetype)sharedInstance {
    
    static CommonUserInfo *instance;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        
        instance = [[CommonUserInfo alloc] init];
        
    });
    
    return instance;
    
}

#pragma mark -是否登录
- (void)setIsLogin:(BOOL)isLogin {
    
    [[NSUserDefaults standardUserDefaults] setBool:isLogin forKey:UserDefaul_isLogin];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
- (BOOL)isLogin {
    
    return [[NSUserDefaults standardUserDefaults] boolForKey:UserDefaul_isLogin];
    
}


#pragma mark -电话号码
- (void)setPhone:(NSString *)phone {
    
    [[NSUserDefaults standardUserDefaults] setValue:phone forKey:UserDefault_Phone];
    [[NSUserDefaults standardUserDefaults] synchronize];

}

- (NSString *)phone {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_Phone];
}

#pragma mark -是否设置支付密码
- (void)setIs_setPayPassword:(BOOL)is_setPayPassword {
    
    [[NSUserDefaults standardUserDefaults] setBool:is_setPayPassword forKey:UserDefault_Is_setPayPassword];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
- (BOOL)is_setPayPassword {
    
    return [[NSUserDefaults standardUserDefaults] boolForKey:UserDefault_Is_setPayPassword];
}

#pragma mark -会员等级
- (void)setVIPLevel:(NSString *)VIPLevel {
    
    [[NSUserDefaults standardUserDefaults] setValue:VIPLevel forKey:UserDefault_VIPLevel];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)VIPLevel {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_VIPLevel];
    
}

#pragma mark -头像URL
- (void)setPhotoUrl:(NSString *)photoUrl {
    
    [[NSUserDefaults standardUserDefaults] setValue:photoUrl forKey:UserDefault_PhotoUrl];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)photoUrl {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_PhotoUrl];
    
}

- (void)setLv:(NSString *)lv {
    [[NSUserDefaults standardUserDefaults] setValue:lv forKey:UserDefault_UserLv];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)lv {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_UserLv];
}

#pragma mark -头像
- (void)setIconIV:(UIImage *)iconIV {
  
    [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(iconIV) forKey:UserDefault_IconIV];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (UIImage *)iconIV {
    
    NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:UserDefault_IconIV];
    
    return [UIImage imageWithData:imageData];
}

#pragma mark -余额
- (void)setBalance:(NSString *)balance {
    
    [[NSUserDefaults standardUserDefaults] setValue:balance forKey:UserDefault_Balance];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)balance {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_Balance];
    
}

- (void)setUser_type:(NSString *)user_type {
    [[NSUserDefaults standardUserDefaults] setValue:user_type forKey:UserDefault_UserType];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)user_type {
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_UserType];
}


- (void)setBean_quota:(NSString *)bean_quota {
    [[NSUserDefaults standardUserDefaults] setValue:bean_quota forKey:UserDefault_Bean_quota];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)bean_quota {
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_Bean_quota];
}

#pragma mark -积分
- (void)setBeanNum:(NSString *)beanNum {
    
    [[NSUserDefaults standardUserDefaults] setValue:beanNum forKey:UserDefault_BeanNum];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)beanNum {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_BeanNum];
    
}

#pragma mark -用户token
- (void)setToken:(NSString *)token {
    
    [[NSUserDefaults standardUserDefaults] setValue:token forKey:UserDefault_Token];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
- (NSString *)token {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_Token];
    
}
#pragma mark -用户token
- (void)setUser_id:(NSString *)user_id {
    
    [[NSUserDefaults standardUserDefaults] setValue:user_id forKey:UserDefault_User_id];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
- (NSString *)user_id {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_User_id];
    
}

#pragma mark -是否绑定支付宝
- (void)setIs_Bind:(BOOL)is_Bind {
    
    [[NSUserDefaults standardUserDefaults] setBool:is_Bind forKey:UserDefault_Is_Bind];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (BOOL)is_Bind {
    
    return [[NSUserDefaults standardUserDefaults] boolForKey:UserDefault_Is_Bind];
    
}

#pragma mark -昵称
- (void)setNickName:(NSString *)nickName {
   
    [[NSUserDefaults standardUserDefaults] setValue:nickName forKey:UserDefault_NickName];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)nickName {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_NickName];
}


#pragma mark -用户信息
- (void)setUserInfoModel:(UserInfoModel *)userInfoModel {
    
    NSDictionary *dict = userInfoModel.mj_keyValues;
    
    [[NSUserDefaults standardUserDefaults] setObject:dict forKey:UserDefault_UserInforModel];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (UserInfoModel *)userInfoModel {
    
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_UserInforModel];
    UserInfoModel *m = [UserInfoModel mj_objectWithKeyValues:dict];
    return m;
    
}

#pragma mark -微信access_token
- (void)setAccess_token:(NSString *)access_token {
    
    [[NSUserDefaults standardUserDefaults] setObject:access_token forKey:UserDefault_Access_token];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)access_token {
    
   return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_Access_token];
    
}

#pragma mark -微信openID
- (void)setOpenID:(NSString *)openID {
    
    [[NSUserDefaults standardUserDefaults] setObject:openID forKey:UserDefault_OpenID];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

- (NSString *)openID {
    
    return [[NSUserDefaults standardUserDefaults] valueForKey:UserDefault_OpenID];
    
}


@end
